package com.cincc.cinccimdemo.ui.me;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.Log;
import android.widget.ImageView;

import com.cincc.cinccimdemo.R;
import com.cincc.cinccimdemo.ui.IMBaseActivity;
import com.king.zxing.util.CodeUtils;

import org.json.JSONObject;

public class QRCodeActivity extends IMBaseActivity {
    private static final String TAG = "QRCodeActivity";

    @Override
    protected int contentLayout() {
        return R.layout.qrcode_activity;
    }

    @Override
    protected void bindViews() {
        super.bindViews();
        try {
            int type = getIntent().getIntExtra("type", 0);
            String targetId = getIntent().getStringExtra("targetId");
            JSONObject j = new JSONObject();
            j.put("type", type);
            j.put("targetId", targetId);
            ImageView imageView = findViewById(R.id.qrCodeImageView);
            Bitmap bitmap = CodeUtils.createQRCode(j.toString(), 400);
            imageView.setImageBitmap(bitmap);
        } catch (Exception e) {
            Log.e(TAG, "bindViews: " + e);
        }
    }

    public static void startQrcode(Context context, int type, String targetId) {
        Intent i = new Intent(context, QRCodeActivity.class);
        i.putExtra("type", type);
        i.putExtra("targetId", targetId);
        context.startActivity(i);
    }
}
